package us.icitap.commandcenter.utils;

import us.icitap.commandcenter.CommandCenterUI;
import us.icitap.commandcenter.listeners.SearchListener;
import us.icitap.commandcenter.ui.custom.CustButton;

import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Runo;


public class OfficerComponent extends CustomLayout {

	private final CustButton searchButton = new CustButton();
	
	private SearchOfficerWindow searchOfficerWindow = new SearchOfficerWindow();
	
	
	
	public OfficerComponent() {
		super("officerLayout");
		this.setWidth("500px");
		this.addComponent(searchButton, "search");
		
		searchButton.addClickListener(new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				CommandCenterUI.getCurrent().addWindow(searchOfficerWindow);
				
			}
		});
		
		searchButton.setStyleName(Runo.BUTTON_LINK);
		searchButton.setIcon(new ThemeResource("img/icons/blue/Search.png"));
		//searchButton.setSizeUndefined();
		this.searchOfficerWindow.addSearchListener(new SearchListener() {
			
			@Override
			public <T> void searchFinished(T result) {
				AppOfficer appOfficer = (AppOfficer) result;
				setOfficer(appOfficer.getOfficer().getPoliceId() + ", " + appOfficer.getOfficer().getNameSurname(), appOfficer.getOrgStructure().getName());
				
			}
		});
		
	}
	
	public OfficerComponent(String officer, String orgStructure) {
		this();
		this.setOfficer(officer, orgStructure);
	}
	
	
	public void setOfficer(String officer, String orgStructure){
		Label lOfficer = new Label(officer);
		Label lOrgStructure = new Label(orgStructure);
		this.removeComponent("officer");
		this.removeComponent("orgStructure");
		this.addComponent(lOfficer,"officer");
		this.addComponent(lOrgStructure, "orgStructure");
		
	}
	
	
	
	
	
	
	
	
	
	
	
}
